package com.william.jdbcplus.core.parallel;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class ExecuteMapperTest {

	public Long execute(Long key) {
		Random random = new Random();
		int time = random.nextInt(100) * 10;
		try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
		}
		System.out.println("线程参数：" + key + " 执行时间：" + time);
		return key * 100;
	}

	public static void main(String[] args) {
		ExecuteMapperTest task = new ExecuteMapperTest();
		List<Long> list = new LinkedList<>();
		for (int i = 0; i < 100; i++) {
			list.add((long) i);
		}

		try {
			List<Long> resultList = ParallelMapperEngine.getInstance().executeToList(list, e -> task.execute(e));
			Map<Long, Long> resultMap = ParallelMapperEngine.getInstance().executeToMap(list, e -> task.execute(e));
			System.out.println(resultList);
			for (Map.Entry<Long, Long> entry : resultMap.entrySet()) {
				System.out.println(entry.getKey() + ":" + entry.getValue());
			}
		} catch (Exception e) {
		}
	}

}
